const Service = require('egg').Service;

module.exports = app => {
  return class BannerService extends Service {
    async list(pageNo = 1, pageSize = 10) {
      const app = this.app;
      const ctx = this.ctx;
      let options = {
        offset: (pageNo - 1) * pageSize,
        limit: pageSize
      };
      return await ctx.model.Article.findAndCountAll(options);
    }

    /**
     * @description 获取所有轮播图
     * @author xiezuobing[948466]<435321508@qq.com>
     * @returns  
     */
    async all() {
      return await this.ctx.model.Banner.findAll();
    }

    /**
     * @description 创建
     * @author xiezuobing[948466]<435321508@qq.com>
     * @param {any} values 
     * @returns  
     */
    async create(values){
      return await this.ctx.model.Banner.create(values);
    }

    /**
     * @description 更新
     * @author xiezuobing[948466]<435321508@qq.com>
     * @param {any} values 
     * @returns  
     */
    async update(values) {
      return await  this.ctx.model.Banner.update(values, {
          where: {
            id: values.id
          }
        });
    }

    /**
     * @description 删除
     * @author xiezuobing[948466]<435321508@qq.com>
     * @param {any} bannerId 
     * @returns  
     */
    async delete(bannerId) {
      return await this.ctx.model.Banner.destroy({
          where: {
            id: bannerId
          }
        })
    }
  }
}